﻿Imports System.Web.UI.WebControls
Imports System.ComponentModel
Imports System.Web.UI

<Serializable()> _
Public Class ItemColuna


#Region "Variaveis"
    Private strCabecalho As String
    Private strNomeColuna As String
    Private strLinkNomeColuna1 As String
    Private strLinkNomeColuna2 As String

    Private strLinkNomePropriedade1 As String
    Private strLinkNomePropriedade2 As String
    Private strLinkNomePropriedade3 As String

    Private strNomeColunaEdicao As String
    Private strTextoFixoLink As String
    Private bolPermiteEdicao As Boolean
    Private bolExibirLink As Boolean
    Private bolObrigatorio As Boolean = True
    Private strURL As String
    Private eTipoDado As eTipoValor = eTipoValor.Texto
    Private haAlinhamentoHorizontal As HorizontalAlign = HorizontalAlign.Left
    Private vaAlinhamentoVertical As VerticalAlign = VerticalAlign.Middle
    Private strHeaderCssClass As String
    Private strItemCssClass As String
    Private strEditItemCssClass As String
    Private intLargura As Integer
    Private intTamanhoMaximo As Integer
    Private eTipoObjetoEdicao As eTipoObjeto = Componentes.eTipoObjeto.TextBoxCarga
    Private strListaOpcoes As String = String.Empty
    Private strMetodoCargaListaOpcoes As String = String.Empty
    Private strDataTableCargaListaOpcoes As String = String.Empty
    Private strCampoValorCargaListaOpcoes As String = String.Empty
    Private strCampoTextoCargaListaOpcoes As String = String.Empty
    Private strFormatoApresentacao As String = String.Empty
    Private strMascaraInput As String
    Private bolTotalizar As Boolean
    Private lngQuantidadeLinhas As Long = 1
    Private objValorDefault As Object = String.Empty
    Private strNomeArquivo As String = String.Empty
    Private blnHabilitarBusca As Boolean
    Protected WithEvents btbBotaoBusca As New ButtonBuscaCarga

#End Region

#Region "Propriedades Principais da Coluna"
    <Category("Coluna"), _
    DefaultValue(GetType(String), ""), _
    DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
    Public Property Cabecalho() As String
        Get
            Return strCabecalho
        End Get
        Set(ByVal Value As String)
            strCabecalho = Value
        End Set
    End Property

    <Category("Coluna"), _
    DefaultValue(GetType(String), ""), _
    DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
    Public Property NomeColuna() As String
        Get
            Return strNomeColuna
        End Get
        Set(ByVal Value As String)
            strNomeColuna = Value
        End Set
    End Property

    <Category("Coluna"), _
    DefaultValue(GetType(String), ""), _
    DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
    Public Property NomeColunaEdicao() As String
        Get
            Return strNomeColunaEdicao
        End Get
        Set(ByVal Value As String)
            strNomeColunaEdicao = Value
        End Set
    End Property

    <Category("Coluna"), _
  DefaultValue(GetType(String), ""), _
  DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
  Public Property TipoDado() As MDP.Framework.Componentes.eTipoValor
        Get
            Return Me.eTipoDado
        End Get
        Set(ByVal value As MDP.Framework.Componentes.eTipoValor)
            Me.eTipoDado = value
        End Set

    End Property

    <Category("Coluna"), _
DefaultValue(GetType(String), ""), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
Public Property ValorDefault() As Object
        Get
            Return Me.objValorDefault
        End Get
        Set(ByVal value As Object)
            Me.objValorDefault = value
        End Set
    End Property

    <Category("Coluna-Cálculo"), _
  DefaultValue(GetType(String), ""), _
  DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
  Public Property Totalizar() As Boolean
        Get
            Return Me.bolTotalizar
        End Get
        Set(ByVal value As Boolean)
            Me.bolTotalizar = value
        End Set
    End Property

    <Category("Upload"), _
     DefaultValue(GetType(String), ""), _
     DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
     Public Property NomeColunaNomeArquivo() As String
        Get
            Return Me.strNomeArquivo
        End Get
        Set(ByVal value As String)
            strNomeArquivo = value
        End Set
    End Property

    <Category("Link"), _
   DefaultValue(GetType(String), ""), _
   DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
   Public Property ExibirLink() As Boolean
        Get
            Return bolExibirLink
        End Get
        Set(ByVal value As Boolean)
            bolExibirLink = value
        End Set
    End Property
    ''' <summary>
    ''' Habilita o botão de busca para ser utilizado no GridCarga
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    <Category("Busca"), _
     DefaultValue(GetType(String), ""), _
     DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
     Public Property HabilitarBusca() As Boolean
        Get
            Return blnHabilitarBusca
        End Get
        Set(ByVal value As Boolean)
            blnHabilitarBusca = value
        End Set
    End Property
    ''' <summary>
    ''' Definine a instância do button busca carga
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    <Category("Busca"), _
     DesignerSerializationVisibility(DesignerSerializationVisibility.Visible), _
      PersistenceMode(PersistenceMode.InnerProperty)> _
     Public Property BotaoBusca() As ButtonBuscaCarga
        Get
            Return btbBotaoBusca
        End Get
        Set(ByVal value As ButtonBuscaCarga)
            btbBotaoBusca = value
        End Set
    End Property
    <Category("Link"), _
   DefaultValue(GetType(String), ""), _
   DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
   Public Property TextoFixoLink() As String
        Get
            Return strTextoFixoLink
        End Get
        Set(ByVal value As String)
            strTextoFixoLink = value
        End Set
    End Property

    <Category("Link"), _
   DefaultValue(GetType(String), ""), _
   DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
   Public Property NomeColuna1() As String
        Get
            Return Me.strLinkNomeColuna1
        End Get
        Set(ByVal value As String)
            Me.strLinkNomeColuna1 = value
        End Set
    End Property

    <Category("Link"), _
   DefaultValue(GetType(String), ""), _
   DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
   Public Property NomeColuna2() As String
        Get
            Return Me.strLinkNomeColuna2
        End Get
        Set(ByVal value As String)
            Me.strLinkNomeColuna2 = value
        End Set
    End Property

    <Category("Link"), _
   DefaultValue(GetType(String), ""), _
   DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
   Public Property NomePropriedade1() As String
        Get
            Return Me.strLinkNomePropriedade1
        End Get
        Set(ByVal value As String)
            Me.strLinkNomePropriedade1 = value
        End Set
    End Property

    <Category("Link"), _
DefaultValue(GetType(String), ""), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
Public Property NomePropriedade2() As String
        Get
            Return Me.strLinkNomePropriedade2
        End Get
        Set(ByVal value As String)
            Me.strLinkNomePropriedade2 = value
        End Set
    End Property

    <Category("Link"), _
DefaultValue(GetType(String), ""), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
Public Property NomePropriedade3() As String
        Get
            Return Me.strLinkNomePropriedade3
        End Get
        Set(ByVal value As String)
            Me.strLinkNomePropriedade3 = value
        End Set
    End Property


    <Category("Link"), _
 DefaultValue(GetType(String), ""), _
 DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
  Public Property URL() As String
        Get
            Return Me.strURL
        End Get
        Set(ByVal value As String)
            strURL = value
        End Set
    End Property

#End Region

#Region "Propriedades de Edição"
    <Category("Edição"), _
    DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
    Public Property TipoControle() As eTipoObjeto
        Get
            Return eTipoObjetoEdicao
        End Get
        Set(ByVal Value As eTipoObjeto)
            eTipoObjetoEdicao = Value
        End Set
    End Property

    <Category("Edição"), _
 DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
 Public Property MascaraInput() As String
        Get
            Return Me.strMascaraInput
        End Get
        Set(ByVal Value As String)
            Me.strMascaraInput = Value
        End Set
    End Property

    <Category("Edição"), _
    DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
    Public Property Obrigatorio() As Boolean
        Get
            Return bolObrigatorio
        End Get
        Set(ByVal Value As Boolean)
            bolObrigatorio = Value
        End Set
    End Property

    <Category("Edição"), _
 DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
 Public Property QuantidadeLinhas() As Long
        Get
            Return Me.lngQuantidadeLinhas
        End Get
        Set(ByVal Value As Long)
            Me.lngQuantidadeLinhas = Value
        End Set
    End Property


    <Category("Edição-DropDownlist"), _
    DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
    Public Property ListaOpcoes() As String
        Get
            Return strListaOpcoes
        End Get
        Set(ByVal Value As String)
            strListaOpcoes = Value
        End Set
    End Property

    <Category("Edição-DropDownlist"), _
    DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
    Public Property MetodoCargaListaOpcoes() As String
        Get
            Return strMetodoCargaListaOpcoes
        End Get
        Set(ByVal Value As String)
            strMetodoCargaListaOpcoes = Value
        End Set
    End Property

    <Category("Edição-DropDownlist"), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
Public Property DataTableCargaListaOpcoes() As String
        Get
            Return strDataTableCargaListaOpcoes
        End Get
        Set(ByVal Value As String)
            strDataTableCargaListaOpcoes = Value
        End Set
    End Property

    <Category("Edição-DropDownlist"), _
    DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
    Public Property CampoValorCargaListaOpcoes() As String
        Get
            Return strCampoValorCargaListaOpcoes
        End Get
        Set(ByVal Value As String)
            strCampoValorCargaListaOpcoes = Value
        End Set
    End Property

    <Category("Edição-DropDownlist"), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
Public Property CampoTextoCargaListaOpcoes() As String
        Get
            Return strCampoTextoCargaListaOpcoes
        End Get
        Set(ByVal Value As String)
            strCampoTextoCargaListaOpcoes = Value
        End Set
    End Property

    <Category("Edição"), _
DefaultValue(GetType(String), ""), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
Public Property TamanhoMaximo() As Integer
        Get
            Return Me.intTamanhoMaximo
        End Get
        Set(ByVal value As Integer)
            Me.intTamanhoMaximo = value
        End Set
    End Property

    <Category("Edição"), _
    DefaultValue(GetType(String), ""), _
    DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
    Public Property PermiteEdicao() As Boolean
        Get
            Return bolPermiteEdicao
        End Get
        Set(ByVal Value As Boolean)
            bolPermiteEdicao = Value
        End Set
    End Property

#End Region

#Region "Propriedades de Aparência e Estilo"
    <Category("Coluna-Aparência"), _
DefaultValue(GetType(String), ""), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
Public Property FormatoApresentacao() As String
        Get
            Return Me.strFormatoApresentacao
        End Get
        Set(ByVal value As String)
            Me.strFormatoApresentacao = value
        End Set
    End Property


    <Category("Coluna-Estilos"), _
 DefaultValue(GetType(String), ""), _
 DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
 Public Property HeaderCssClass() As String
        Get
            Return Me.strHeaderCssClass
        End Get
        Set(ByVal value As String)
            Me.strHeaderCssClass = value
        End Set
    End Property

    <Category("Coluna-Estilos"), _
    DefaultValue(GetType(String), ""), _
    DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
    Public Property ItemCssClass() As String
        Get
            Return Me.strItemCssClass
        End Get
        Set(ByVal value As String)
            Me.strItemCssClass = value
        End Set
    End Property

    <Category("Coluna-Estilos"), _
    DefaultValue(GetType(String), ""), _
    DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
    Public Property EditItemCssClass() As String
        Get
            Return Me.strEditItemCssClass
        End Get
        Set(ByVal value As String)
            Me.strEditItemCssClass = value
        End Set
    End Property

    <Category("Coluna-Aparência"), _
    DefaultValue(GetType(String), ""), _
    DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
    Public Property Largura() As Integer
        Get
            Return Me.intLargura
        End Get
        Set(ByVal value As Integer)
            Me.intLargura = value
        End Set
    End Property

    <Category("Coluna-Aparência"), _
DefaultValue(GetType(String), ""), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
Public Property AlinhamentoHorizontal() As HorizontalAlign
        Get
            Return Me.haAlinhamentoHorizontal
        End Get
        Set(ByVal value As HorizontalAlign)
            Me.haAlinhamentoHorizontal = value
        End Set
    End Property

    <Category("Coluna-Aparência"), _
DefaultValue(GetType(String), ""), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
Public Property AlinhamentoVertical() As VerticalAlign
        Get
            Return Me.vaAlinhamentoVertical
        End Get
        Set(ByVal value As VerticalAlign)
            Me.vaAlinhamentoVertical = value
        End Set
    End Property

#End Region

    Public Sub New()

        Me.strCabecalho = ""
        Me.strNomeColuna = ""
        Me.strLinkNomeColuna1 = ""
        Me.strLinkNomeColuna2 = ""
        Me.strLinkNomePropriedade1 = ""
        Me.strLinkNomePropriedade2 = ""
        Me.strLinkNomePropriedade3 = ""
        Me.strNomeColunaEdicao = ""
        Me.strTextoFixoLink = ""
        Me.bolPermiteEdicao = True
        ' Me.bolExibirLink = False
        Me.bolObrigatorio = True
        Me.strURL = ""
        Me.strItemCssClass = ""
        Me.strEditItemCssClass = ""
        '        Me.intLargura = 0
        Me.strMetodoCargaListaOpcoes = ""
        Me.strDataTableCargaListaOpcoes = ""
        Me.strCampoTextoCargaListaOpcoes = ""
        Me.strCampoValorCargaListaOpcoes = ""
        Me.strFormatoApresentacao = ""
        Me.strMascaraInput = String.Empty
        'Me.bolTotalizar = False
        Me.strNomeArquivo = String.Empty

    End Sub

    Public Function OpcoesToItemCarga(ByVal strListadeOpcoes As String) As ItemCarga()

        Dim strOpcoes() As String
        Dim Itens() As ItemCarga

        strOpcoes = strListadeOpcoes.Split(";")

        ReDim Itens(strOpcoes.Length - 1)

        For Each strOpcao As String In strOpcoes

            Dim Valor, Texto As String

            If strOpcao.Split(",").Length = 2 Then
                Valor = strOpcao.Split(",")(0)
                Texto = strOpcao.Split(",")(1)
            Else
                Valor = strOpcao
                Texto = strOpcao
            End If

            Itens(Array.IndexOf(strOpcoes, strOpcao)) = New ItemCarga(Texto, Valor, False)

        Next

        Return Itens

    End Function
End Class